package com.iot.manager.network;

import com.iot.manager.data.models.Device;
import com.iot.manager.data.models.DeviceConfig;
import com.iot.manager.data.models.DeviceData;
import com.iot.manager.data.models.DeviceListResponse;
import com.iot.manager.data.models.DeviceStats;
import com.iot.manager.data.models.HealthResponse;
import com.iot.manager.data.models.LoginRequest;
import com.iot.manager.data.models.LoginResponse;
import com.iot.manager.data.models.PasswordChangeRequest;
import com.iot.manager.data.models.RegisterRequest;
import com.iot.manager.data.models.RegisterResponse;
import com.iot.manager.data.models.User;

import java.util.Date;
import java.util.List;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface ApiService {
    // 健康检查
    @GET("health")
    Call<HealthResponse> checkHealth();

    // 认证相关
    @POST("auth/register")
    Call<RegisterResponse> register(@Body RegisterRequest request);

    @POST("auth/login")
    Call<LoginResponse> login(@Body LoginRequest request);

    @GET("auth/me")
    Call<User> getCurrentUser();

    @PUT("auth/users/me")
    Call<User> updateUser(@Body User user);

    @PUT("auth/users/me/password")
    Call<Void> changePassword(@Body PasswordChangeRequest request);

    // 设备管理
    @GET("devices")
    Call<List<Device>> getDevices();

    @GET("devices/stats")
    Call<DeviceStats> getDeviceStats();

    @GET("devices/{deviceId}")
    Call<Device> getDevice(@Path("deviceId") String deviceId);

    @POST("devices")
    Call<Device> createDevice(@Body Device device);

    @POST("devices/register")
    Call<Device> registerDevice(@Body Device device);

    @PUT("devices/{deviceId}")
    Call<Device> updateDevice(@Path("deviceId") String deviceId, @Body Device device);

    @DELETE("devices/{deviceId}")
    Call<ResponseBody> deleteDevice(@Path("deviceId") String deviceId);

    // 设备数据
    @GET("devices/{deviceId}/data")
    Call<List<DeviceData>> getDeviceData(
        @Path("deviceId") String deviceId,
        @Query("startTime") Date startTime,
        @Query("endTime") Date endTime
    );
    @GET("devices/{deviceId}/data")
    Call<List<DeviceData>> getDeviceDataByTimeRange(
        @Path("deviceId") String deviceId,
        @Query("startTime") Date startTime,
        @Query("endTime") Date endTime
    );
    @POST("devices/{deviceId}/data")
    Call<ResponseBody> saveDeviceData(
        @Path("deviceId") String deviceId,
        @Body DeviceData data
    );

    // 设备命令
    @POST("devices/{deviceId}/command")
    Call<ResponseBody> sendCommand(
        @Path("deviceId") String deviceId,
        @Query("command") String command,
        @Query("params") String params
    );

    // 设备配置
    @GET("devices/{deviceId}/config")
    Call<DeviceConfig> getDeviceConfig(@Path("deviceId") String deviceId);

    @PUT("devices/{deviceId}/config")
    Call<DeviceConfig> updateDeviceConfig(
        @Path("deviceId") String deviceId,
        @Body DeviceConfig config
    );

    // 固件更新
    @Multipart
    @POST("devices/{deviceId}/firmware")
    Call<ResponseBody> updateFirmware(
        @Path("deviceId") String deviceId,
        @Part MultipartBody.Part firmware
    );

    // 文件上传
    @Multipart
    @POST("devices/{deviceId}/file")
    Call<ResponseBody> uploadFile(
        @Path("deviceId") String deviceId,
        @Part MultipartBody.Part file,
        @Part("fileType") RequestBody fileType
    );

    @GET("devices/{deviceId}/data")
    Call<List<DeviceData>> getDeviceHistoryData(
        @Path("deviceId") String deviceId,
        @Query("startTime") String startTime,
        @Query("endTime") String endTime
    );
} 